package com.zmj.controller;

import com.zmj.dto.TableData;
import com.zmj.entity.SysRole;
import com.zmj.service.SysMenuService;
import com.zmj.service.SysRoleService;
import com.zmj.utils.Response;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@RestController
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;
    @RequestMapping("/sys/role/list")
    public TableData findRoleAll(String search , String order, int offset, int limit){
        return sysRoleService.findRoleAll(search,order,offset,limit);
    }

    @RequestMapping("/sys/role/save")
    public Response saveRole(@RequestBody SysRole sysRole, HttpSession session){
        long id = (long) session.getAttribute("USERID");
        sysRole.setCreateUserId(id);
        sysRole.setCreateTime(new Date());
        return sysRoleService.saveRole(sysRole);
    }

    @RequestMapping("/sys/role/info/{roleId}")
    public Response roleInfo(@PathVariable long roleId){
        return sysRoleService.roleInfo(roleId);
    }

    @RequestMapping("/sys/role/update")
    public Response updata(@RequestBody SysRole sysRole){
        return sysRoleService.updata(sysRole);
    }

    @RequestMapping("/sys/role/del")
    public Response del(@RequestBody List<Long> ids){
        return sysRoleService.del(ids);
    }


    @RequestMapping("/sys/user/notHasRole/{userId}")
    public Response roles(@PathVariable long userId){

        return   sysRoleService.userNotHasRole(userId);

    }
    @RequestMapping("/sys/user/addRole/{userId}/{roleId}")
    public Response addRole(@PathVariable long userId,@PathVariable long roleId){
        return sysRoleService.insertUserRole(userId,roleId);
    }
}
